package cst.a113cx.fragmentrecyclerview;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Layout;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import Adapter.AdapterFor_RecyclerView;
import Bean.ArticleBean;
import Retorfit对象.ArticleModel;
import retrofit2.Call;
import retrofit2.Response;

public class MainActivity extends AppCompatActivity {

    ViewPager vp01;
    LinearLayout layout01,layout02,layout03,layout04;
    ImageButton im01,im02,im03,im04;

    private List<Fragment> listf;
    private FragmentPagerAdapter fragmentPagerAdapter;


    void init(){
        vp01=(ViewPager)findViewById(R.id.vp01);

        layout01=(LinearLayout) findViewById(R.id.layout1);
        layout02=(LinearLayout) findViewById(R.id.layout2);
        layout03=(LinearLayout) findViewById(R.id.layout3);
        layout04=(LinearLayout) findViewById(R.id.layout4);

        im01=(ImageButton)findViewById(R.id.imageButton1);
        im02=(ImageButton)findViewById(R.id.imageButton2);
        im03=(ImageButton)findViewById(R.id.imageButton3);
        im04=(ImageButton)findViewById(R.id.imageButton4);

        View.OnClickListener ock2 =new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch(v.getId()) {
                    case R.id.imageButton1:
                        picreset();
                        im01.setImageResource(R.drawable.address_pressed);
                        MyFragment01 m1=new MyFragment01();
                        vp01.setCurrentItem(0);
                        break;
                    case R.id.imageButton2:
                        picreset();
                        im02.setImageResource(R.drawable.friend_pressed);
                        MyFragment02 m2=new MyFragment02();
                        vp01.setCurrentItem(1);
                        break;
                    case R.id.imageButton3:
                        picreset();
                        im03.setImageResource(R.drawable.weixin_pressed);
                        MyFragment03 m3=new MyFragment03();
                        vp01.setCurrentItem(2);
                        break;
                    case R.id.imageButton4:
                        picreset();
                        im04.setImageResource(R.drawable.settings_pressed);
                        MyFragment04 m4=new MyFragment04();
                        vp01.setCurrentItem(3);
                        break;

                }
            }
        };
        im01.setOnClickListener(ock2);
        im02.setOnClickListener(ock2);
        im03.setOnClickListener(ock2);
        im04.setOnClickListener(ock2);

    }

    void picreset(){
        im01.setImageResource(R.drawable.address_normal);
        im02.setImageResource(R.drawable.friend_normal);
        im03.setImageResource(R.drawable.weixin_normal);
        im04.setImageResource(R.drawable.settings_normal);
    }

    void  initfragment(){
        listf=new ArrayList<Fragment>();
        listf.add(new MyFragment01());
        listf.add(new MyFragment02());
        listf.add(new MyFragment03());
        listf.add(new MyFragment04());
        fragmentPagerAdapter=new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return listf.get(position);
            }

            @Override
            public int getCount() {
                return listf.size();
            }
        };
        vp01.setAdapter(fragmentPagerAdapter);




    }

    View.OnClickListener onk=new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if(v.getId()==R.id.layout1){

                //ib01.setImageResource(R.drawable.weixin_pressed);

                MyFragment01 m1=new MyFragment01();

                vp01.setCurrentItem(0);
            }
            else if(v.getId()==R.id.layout2){
                //ib02.setImageResource(R.drawable.address_pressed);
                MyFragment02 m2=new MyFragment02();
                //m2.onCreateView()
                vp01.setCurrentItem(1);
            }
            else if(v.getId()==R.id.layout3){

                MyFragment03 m3=new MyFragment03();

                vp01.setCurrentItem(2);
            }
            else if(v.getId()==R.id.layout4){
                //ib02.setImageResource(R.drawable.address_pressed);
                MyFragment04 m4=new MyFragment04();
                //m2.onCreateView()
                vp01.setCurrentItem(3);
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
        initfragment();

    }
}
